<template>
  <div class="serial-editor-wrap">
    <div class="editor-header">
      <h5>{{ $t("config.InternationalSetting") }}</h5>
    </div>
    <div class="editor-content">
      <g-detail
        ref="detail"
        :inputConfig="inputConfig"
        :rules="rules"
        @changeDetail="changeDetail"
      ></g-detail>
    </div>
  </div>
</template>

<script>
import baseMixin from "@/mixins/BaseMixin";
export default {
  name: "internationEditor",
  mixins: [baseMixin],
  props: {
    id: {
      type: Number,
    },
    data: {
      type: Object,
    },
  },
  data() {
    return {
      detail: {
        enabledYear: 1,
        enabledMonth: 1,
        enabledDay: 1,
      },
      inputConfig: [
        {
          type: "select",
          label: this.$t("config.tblname"),
          props: "tblname",
          options: this.getOptions("codelkup/TblName"),
        },
        {
          type: "select",
          label: this.$t("config.locale"),
          props: "locale",
          options: this.getOptions("codelkup/Locale"),
        },
        {
          type: "select",
          label: this.$t("security.wareHouse"),
          props: "whseid",
          options: this.getOptions("queryActionWmwhse"),
          break: true,
        },
        {
          type: "input",
          label: this.$t("config.joinkey", { no: 1 }),
          props: "joinkey1",
        },
        {
          type: "input",
          label: this.$t("config.joinkey", { no: 2 }),
          props: "joinkey2",
        },
        {
          type: "input",
          label: this.$t("config.joinkey", { no: 3 }),
          props: "joinkey3",
        },
        {
          type: "input",
          label: this.$t("config.joinkey", { no: 4 }),
          props: "joinkey4",
        },
        {
          type: "input",
          label: this.$t("config.joinkey", { no: 5 }),
          props: "joinkey5",
          break: true,
        },
        {
          type: "input",
          label: this.$t("config.localeCode"),
          props: "code",
        },
        {
          type: "input",
          label: this.$t("config.localDesc"),
          props: "description",
          break: true,
        },
        {
          type: "textarea",
          label: this.$t("app.remark"),
          props: "remark",
        },
      ],
      rules: {
        tblname: [
          {
            required: true,
            message: this.$selectPlease("config.tblname"),
            trigger: "blur",
          },
        ],
        locale: [
          {
            required: true,
            message: this.$selectPlease("config.locale"),
            trigger: "blur",
          },
        ],
        whseid: [
          {
            required: true,
            message: this.$selectPlease("security.wareHouse"),
            trigger: "blur",
          },
        ],
        joinkey1: [
          {
            required: true,
            message: this.$inputPlease("config.joinkey", { no: 1 }),
            trigger: "blur",
          },
        ],
        code: [
          {
            required: true,
            message: this.$inputPlease("config.localeCode"),
            trigger: "blur",
          },
        ],
        description: [
          {
            required: true,
            message: this.$inputPlease("config.serialCount"),
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    changeDetail(detail, prop) {
      this.inputConfig.find(item => item.props == prop).defaultValue = detail[prop]
      if(prop == 'tblname'){
        const index = this.inputConfig.findIndex(item => item.props == "whseid");
        if(['13902','13903'].includes(detail.tblname)){
          this.$set(this.inputConfig[index],'defaultValue','enterprise')
          this.$set(this.inputConfig[index],'disabled',true)
          detail.whseid = 'enterprise';
        }else{
          this.$set(this.inputConfig[index],'defaultValue','')
          this.$set(this.inputConfig[index],'disabled',false)
          // detail.whseid = '';
        }
      }
      this.$emit("update:data", detail);
    },
    getSerialInfo() {
      this.inputConfig.forEach((item, index) => {
        this.$set(
          this.inputConfig[index],
          "defaultValue",
          this.data[item.props]
        );
        // item.defaultValue = this.data[item.props]
        this.changeDetail(this.data, item.props);
      });
    },
  },
  watch: {
    data: {
      handler(data) {
        if (data) {
          this.getSerialInfo();
        }
      },
      deep: true,
      immediate: true,
    },
  },
};
</script>

<style lang="scss" scoped>
.serial-editor-wrap {
  border: 1px solid #dddddd;
  .editor-header {
    padding: 5px;
    background: #eff3f7;
    border-bottom: 1px solid #dddddd;
  }
  h4 {
    position: relative;
    padding-left: 1em;
    &::before {
      content: "";
      position: absolute;
      width: 4px;
      height: 1em;
      left: 0;
      background: #409eff;
    }
  }
  .editor-content {
    padding: 10px;
  }
}
</style>
